//
// Created by yangchao on 2022/6/3.
// 121. 买卖股票的最佳时机: https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/
//

#include <vector>
#include <climits>

using namespace std;

class MaxProfit {
public:
    int maxProfit(vector<int>& prices) {
        int minprice = INT_MAX, maxprofit = 0;
        for (int price: prices) {
            maxprofit = max(maxprofit,price-minprice);
            minprice = min(price,minprice);
        }
        return maxprofit;
    }
};
